package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationTemplateContract;
import com.minimalist.common.entity.lindi.vo.tradeapplicationtemplatecontract.LindiTradeApplicationTemplateContractQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 林地指标交易平台_交易申请合同模板 映射层。
 *
 * @author 11987
 * @since 2025-06-04
 */
@Mapper
public interface LindiTradeApplicationTemplateContractMapper extends BaseMapper<LindiTradeApplicationTemplateContract>{

    /**
     * 根据交易申请合同模板ID查询交易申请合同模板
     *
     * @param tradeApplicationTemplateContractId 交易申请合同模板ID
     * @return 交易申请合同模板
     */
    default LindiTradeApplicationTemplateContract
    selectTradeApplicationTemplateContractByTradeApplicationTemplateContractId(
            Long tradeApplicationTemplateContractId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationTemplateContract::getTradeApplicationContractFileId
                        , tradeApplicationTemplateContractId));
    }

    /**
     * 分页查询交易申请合同模板列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiTradeApplicationTemplateContract> selectPageTradeApplicationTemplateContractList(LindiTradeApplicationTemplateContractQueryVO queryVO){
        QueryWrapper queryWrapper = QueryWrapper.create();
        
        // 根据合同模板ID查询
        if (queryVO.getContractTemplateId() != null) {
            queryWrapper.eq(LindiTradeApplicationTemplateContract::getTradeApplicationContractFileId, queryVO.getContractTemplateId());
        }
        
        // 根据文件ID查询
        if (queryVO.getFileId() != null) {
            queryWrapper.eq(LindiTradeApplicationTemplateContract::getFileId, queryVO.getFileId());
        }
        
        // 根据交易申请ID查询
        if (queryVO.getTradeApplicationId() != null) {
            queryWrapper.eq(LindiTradeApplicationTemplateContract::getTradeApplicationId, queryVO.getTradeApplicationId());
        }
        
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(), queryWrapper);
    }

    /**
     * 根据交易申请ID查询交易申请合同模板列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 交易申请合同模板列表
     */
    default List<LindiTradeApplicationTemplateContract> selectTradeApplicationTemplateContractByTradeApplicationId(Long tradeApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationTemplateContract::getTradeApplicationId
                        , tradeApplicationId));
    }
}
